#include <stdio.h>

void dmp2(char *buff, int type)
{
	char currtime[40];
	char tmp_buff[1024];
	int	i;

	getCurTime(currtime);
	if (type == 1){
		printf("%s[%d]SVC:%s\n", currtime, getpid(), buff);
	} else if (type == 2){
		printf("%s[%d]%s\n", currtime, getpid(), buff);
	} else if (type == 3){
		sprintf(tmp_buff, 
			"IFCODE:%02X %02X %02X %02X|"
			"%02X|"
			"%02X %02X|"
			"%02X %02X %02X %02X %02X %02X %02X|"
			"%02X %02X %02X %02X|"
			"%02X %02X",
			(char)*buff,(char)*(buff + 1), (char)*(buff + 2), (char)*(buff + 3),
			(char)*(buff + 4),
			(char)*(buff + 5), (char)*(buff + 6),
			(char)*(buff + 50), (char)*(buff + 51), (char)*(buff + 52), (char)*(buff + 53), (char)*(buff + 54), (char)*(buff + 55), (char)*(buff + 56),
			(char)*(buff + 62), (char)*(buff + 63), (char)*(buff + 64), (char)*(buff + 65), 
			(char)*(buff + 76), (char)*(buff + 77)
		);
		printf("%s[%d]%s\n", currtime, getpid(), tmp_buff);
	}
	fflush(stdout);
}

get_trace_level(char *eval)
{
	int aa;

	aa = atoi( (char *)getenv( eval ) );

}

void dmp(char *buff, int type, int msg_len)
{
	char 	currtime[40];
	char 	tmp_buff[1024];
	char 	tmp_buff2[1024];
	int  	trace_level = 5;
	int		aa;

	trace_level = ((aa = get_trace_level("TRACE_LEVEL")) > 0 ) ? aa : trace_level;
	/*
	printf("%s=%d\n", "TRACE_LEVEL", trace_level);
	*/

	switch (type) {
		case 1 :
				if( type > trace_level ) break;
				sprintf(tmp_buff, "SVC:%s", buff);
				break;
		case 2 :
				if( type > trace_level ) break;
				sprintf(tmp_buff, "%s", buff);
				break;
		case 3 :
				if( type > trace_level ) break;
				sprintf(tmp_buff, 
					"IFCODE:%02X %02X %02X %02X|"
					"%02X|"
					"%02X %02X|"
					"%02X %02X %02X %02X %02X %02X %02X|"
					"%02X %02X %02X %02X|"
					"%02X %02X",
					(char)*buff,(char)*(buff+1),(char)*(buff+2),(char)*(buff+3),
					(char)*(buff + 4),
					(char)*(buff + 5), (char)*(buff + 6),
					(char)*(buff + 50), (char)*(buff + 51), (char)*(buff + 52), 
						(char)*(buff+53), (char)*(buff+54), (char)*(buff + 55),
						(char)*(buff + 56),
					(char)*(buff + 62), (char)*(buff + 63), (char)*(buff + 64), 
						(char)*(buff + 65), 
					(char)*(buff + 76), (char)*(buff + 77)
				);
				break;
		case 8 :
				if( type > trace_level ) break;
				sprintf(tmp_buff, "Message Dump(input)");
				break;
		case 9 :
				if( type > trace_level ) break;
				sprintf(tmp_buff, "Message Dump(output)");
		default :
				break;
	}

	if( type <= trace_level ) {
			getCurTime(currtime);
			sprintf(tmp_buff2, "%s<%d><%d>%s", currtime, getpid(), type, tmp_buff);
			fflush(stdout);
			printf("%s\n", tmp_buff2);

			fflush(stdout);
			if( (type == 8) || (type == 9) )
				HexLog(buff, msg_len);
	}
}

#if 0
main()
{
	int trace_level=8;
	int aa;
	dmp("hello", 1);
	dmp("hello", 8, 10);
	dmp("hello", 9, 10);
	/*
	trace_level = ((aa = get_trace_level("TRACE_LEVEL")) > 0 ) ? aa : trace_level;
	printf("%s=%d\n", "TRACE_LEVEL", trace_level);
	*/
}
#endif
